﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using OsPortal;

/// <summary>
/// Summary description for clsGopY
/// </summary>
public class clsGopY
{
    private const string strClassName = "clsGopY";

    public struct stGOPY
    {
        public Int32 iGY_ID;
        public String strGY_TIEUDE;
        public String strGY_EMAIL;
        public String strGY_NOIDUNG;
        public String strGY_IP_CLIENT;
        public DateTime dGY_NGAYTAO;
    }

    public clsGopY()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    /// <summary>
    /// Thêm mới, sửa, xóa Góp ý
    /// Author: NguyenTV
    /// Create Date: 12/09/2013
    /// </summary>
    /// <param name="strMod">Mod</param>
    /// <param name="objGopY">obj Góp ý</param>
    /// <param name="strError">Biến trả về nếu có lỗi</param>
    /// <param name="strCurrentID"></param>
    /// <returns></returns>
    public static bool GOPY_ACT(string strMod, clsGopY.stGOPY objGopY, out string strError)
    {
        try
        {
            DataTable tblResult;
            tblResult = oSqlDataHelper.sExecuteDataTable("GOPY_ACT", new SqlParameter[]{
                                                     new SqlParameter("@P_MOD",strMod)
                                                    ,new SqlParameter("@P_GY_ID",objGopY.iGY_ID)
                                                    ,new SqlParameter("@P_GY_TIEUDE",objGopY.strGY_TIEUDE)
                                                    ,new SqlParameter("@P_GY_EMAIL",objGopY.strGY_EMAIL)
                                                    ,new SqlParameter("@P_GY_NOIDUNG",objGopY.strGY_NOIDUNG)
                                                    ,new SqlParameter("@P_GY_IP_CLIENT",objGopY.strGY_IP_CLIENT)
            });
            if (tblResult == null) { 
                strError = "";
                clsEmail.Send_Mail_GopY(objGopY.strGY_TIEUDE, objGopY.strGY_EMAIL, objGopY.strGY_NOIDUNG); 
                return true; 
            }
            if (tblResult.Rows.Count <= 0) { 
                strError = "";
                clsEmail.Send_Mail_GopY(objGopY.strGY_TIEUDE, objGopY.strGY_EMAIL, objGopY.strGY_NOIDUNG); 
                return true; 
            }
            //
            strError = OsPortal.oStringHelper.fncCnvNullToString(tblResult.Rows[0]["ERRNAME"]);
            return false;
        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr(strClassName, "GOPY_ACT", ex.ToString());
            strError = "";
            return false;
        }

    }

}